<?php

function getFileInfo($file_post, $i) {

    return array( 'name' => iconv("utf-8", "gb2312", $file_post['name'][$i]),
                  'type' => $file_post['type'][$i],
                  'tmp_name' => $file_post['tmp_name'][$i],
                  'error' => $file_post['error'][$i],
                  'size' => $file_post['size'][$i]);
}

$ds = DIRECTORY_SEPARATOR;

$storeFolder = 'file';

if(!empty($_FILES)) {
    
    if(!is_array($_FILES['file']['name'])) { // 一个表单一个文件
        
        $file = $_FILES['file'];
        
        move_uploaded_file($file['tmp_name'], 
            dirname( __FILE__ ) . $ds. $storeFolder . $ds . iconv("utf-8", "gb2312", $file['name']));        
    }
    
    else {
        
        $cnt = count($_FILES['file']['name']);
        
        for($i = 0; $i < $cnt; $i++) { // 一个表单多个文件
        
            $file = getFileInfo($_FILES['file'], $i);
            
            move_uploaded_file($file['tmp_name'], 
                dirname( __FILE__ ) . $ds. $storeFolder . $ds . $file['name']);
        }           
    }
}
